package top.zsyle.order.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import top.zsyle.order.domain.OrderPetAcquisition;
import top.zsyle.order.domain.OrderProduct;
import top.zsyle.order.dto.ConfirmDto;
import top.zsyle.order.service.IOrderProductService;
import top.zsyle.basic.service.impl.BaseServiceImpl;
import org.springframework.stereotype.Service;
import top.zsyle.pet.domain.SearchMasterMsg;
import top.zsyle.product.domain.ProductMsg;
import top.zsyle.product.mapper.ProductMsgMapper;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zsy
 * @since 2022-12-09
 */
@Service
public class OrderProductServiceImpl extends BaseServiceImpl<OrderProduct> implements IOrderProductService {

    @Autowired
    private ProductMsgMapper productMsgMapper;

    @Override
    public void confirm(ConfirmDto dto) {
        // 修改 收购单状态 1 价格 支付类型
        OrderProduct dataBaseOrder = findById(dto.getId());
        OrderProduct order = new OrderProduct();
        order.setId(dto.getId());
        order.setState(1);
        order.setPrice(dto.getMoney());
        update(order);
        // 修改msg的状态为 2
        ProductMsg msg = new ProductMsg();
        msg.setId(dataBaseOrder.getMsgId());
        msg.setState(2);
        productMsgMapper.update(msg);
    }

    @Override
    public void cancel(Long id) {
        // 修改收购单状态为 -1 取消
        // 通过id 查询到order对象
        OrderProduct dataBaseOrder = findById(id);
        OrderProduct order = new OrderProduct();
        order.setId(id);
        order.setState(-1);
        super.update(order);
        // 修改msg的状态为 0 审核通过 并且把店铺id置空
        ProductMsg msg = new ProductMsg();
        msg.setId(dataBaseOrder.getMsgId());
        msg.setState(0);
        productMsgMapper.update(msg);
    }
}
